package com.Mt.Serviceimpl;

import com.Mt.Service.MtAddressService;
import com.Mt.mapper.MtAddressMapper;
import com.Mt.pojo.MtAddress;
import com.Mt.pojo.Page;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class MtAddressServiceImpl implements MtAddressService {

    @Autowired
    private MtAddressMapper mtAddressMapper;

    // 根据用户ID查询用户的收货地址
    public List<MtAddress> selUserID(String userId) {
        return mtAddressMapper.selUserID(userId);
    }
    // 根据收货地址ID查看详细的信息
    public MtAddress selID(int id) {
        return mtAddressMapper.selID(id);
    }
    // 修改地址信息
    public int upd(MtAddress mtAddress) {
        return mtAddressMapper.upd(mtAddress);
    }
    // 添加新的地址
    public int add(MtAddress mtAddress) {
        return mtAddressMapper.add(mtAddress);
    }

    public Page<MtAddress> pageAddress(String userId,String userName,int index) {
        int size = 10;
        int count = mtAddressMapper.count(userId, userName);
        // 总页数
        int pageEnd = count % size == 0 ? count / size : count / size + 1;
        Page page = new Page();
        page.setCount(count);
        page.setPageEnd(pageEnd);
        page.setData(mtAddressMapper.pageAddress(userId,userName,(index-1)*size,size));
        return page;
    }

}
